package Task7;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()){
            int number = scanner.nextInt();
            int f1 = 0;
            int f2 = 1;
            int f3 = f1 + f2;
            while (f3 < number ){
                f1 = f2;
                f2 = f3;
                f3 = f1 + f2;
            }
            //System.out.println(f1+" "+ f2 +" "+f3 + " ");
            //如果输入的数字为0，则不进入下列的判断直接输出0
            if(number != 0) {
                if (number - f2 < f3 - number) {
                    int count = number - f2;
                    System.out.println(number - f2);
                } else if (number - f2 == 0 || f3 - number == 0) {
                    System.out.println(0);
                } else {
                    System.out.println(f3 - number);
                }
            }else {
                System.out.println(0);
            }
        }
    }
}
